﻿/*
* 实现了图片按钮类.
* 功能是在按钮处于不同的状态时，加载对应的图片.
*
*/

#ifndef IMAGE_PUSH_BUTTON_H
#define IMAGE_PUSH_BUTTON_H

#include <QPushButton>

class ImagePushButton : public QPushButton
{
    Q_OBJECT

public:

    // 枚举按钮的几种状态：
    // 正常，鼠标悬停，按下，无状态.
    typedef enum
    {
        NORMAL = 0,
        ENTER,
        PRESS,
        NOSTATUS
    } ButtonStatus;

    explicit ImagePushButton(QWidget *parent = 0);
    ~ImagePushButton();
    void setImageName(QString &image_name);
    const QString &getImageName() { return m_image_name; }

protected:

    void enterEvent(QEvent *event) Q_DECL_OVERRIDE;
    void leaveEvent(QEvent *event) Q_DECL_OVERRIDE;
    void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
    void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
    void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;

private:

    ButtonStatus m_status;
    QString m_image_name;

    int m_btn_width;            // 按钮宽度
    int m_btn_height;           // 按钮高度
    bool m_leftmouse_pressed;         // 按钮左键是否按下
};

#endif // IMAGE_PUSH_BUTTON_H

